<html>
<head><meta charset="utf-8"><title>termination c vs c++ · general · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/index.html">general</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/termination.20c.20vs.20c.2B.2B.html">termination c vs c++</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="158049029"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/termination%20c%20vs%20c%2B%2B/near/158049029" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/termination.20c.20vs.20c.2B.2B.html#158049029">(Feb 11 2019 at 17:41)</a>:</h4>
<p><span class="user-mention" data-user-id="123586">@nagisa</span> do you have a link to the differences in whether termination is an effect in C but not in C++ ? AFAIK it is also an effect in C++. At least a <code>pure</code>+<code>noreturn</code> function seems to be UB in both: <a href="https://gcc.godbolt.org/z/scPU2t" target="_blank" title="https://gcc.godbolt.org/z/scPU2t">https://gcc.godbolt.org/z/scPU2t</a></p>



<a name="158049130"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/termination%20c%20vs%20c%2B%2B/near/158049130" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/termination.20c.20vs.20c.2B.2B.html#158049130">(Feb 11 2019 at 17:43)</a>:</h4>
<p>well, non-termination is an effect in C, but not C++</p>



<a name="158049136"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/termination%20c%20vs%20c%2B%2B/near/158049136" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/termination.20c.20vs.20c.2B.2B.html#158049136">(Feb 11 2019 at 17:43)</a>:</h4>
<p>specifically because C++ allows optimising out empty loops, but not C.</p>



<a name="158049143"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/termination%20c%20vs%20c%2B%2B/near/158049143" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/termination.20c.20vs.20c.2B.2B.html#158049143">(Feb 11 2019 at 17:44)</a>:</h4>
<p>Did I write it wrong on the issue again?</p>



<a name="158049262"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/termination%20c%20vs%20c%2B%2B/near/158049262" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/termination.20c.20vs.20c.2B.2B.html#158049262">(Feb 11 2019 at 17:45)</a>:</h4>
<p>nah, it seems like whatever I wrote is right, given the ccontext.</p>



<a name="158049809"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/termination%20c%20vs%20c%2B%2B/near/158049809" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/termination.20c.20vs.20c.2B.2B.html#158049809">(Feb 11 2019 at 17:52)</a>:</h4>
<p>ah yes, that's correct</p>



<a name="158049819"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/termination%20c%20vs%20c%2B%2B/near/158049819" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/termination.20c.20vs.20c.2B.2B.html#158049819">(Feb 11 2019 at 17:52)</a>:</h4>
<p>LLVM is broken in that it treats C and Rust as C++</p>



<a name="158049844"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/termination%20c%20vs%20c%2B%2B/near/158049844" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/termination.20c.20vs.20c.2B.2B.html#158049844">(Feb 11 2019 at 17:53)</a>:</h4>
<p>I somehow read it the other way around</p>



<a name="158049938"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/termination%20c%20vs%20c%2B%2B/near/158049938" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/termination.20c.20vs.20c.2B.2B.html#158049938">(Feb 11 2019 at 17:54)</a>:</h4>
<p><span class="user-mention" data-user-id="123586">@nagisa</span> i think that's only for for loops</p>



<a name="158049984"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/termination%20c%20vs%20c%2B%2B/near/158049984" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/termination.20c.20vs.20c.2B.2B.html#158049984">(Feb 11 2019 at 17:55)</a>:</h4>
<p>as in, in C++ infinite loops are UB, in C they are not, but the implementation can assume that they terminate</p>



<a name="158049986"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/termination%20c%20vs%20c%2B%2B/near/158049986" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/termination.20c.20vs.20c.2B.2B.html#158049986">(Feb 11 2019 at 17:55)</a>:</h4>
<p>In C <code>while(x)</code> is required to be considered a side-effect as long as <code>x</code> is constant-ish</p>



<a name="158050009"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/termination%20c%20vs%20c%2B%2B/near/158050009" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/termination.20c.20vs.20c.2B.2B.html#158050009">(Feb 11 2019 at 17:55)</a>:</h4>
<p>that is in C empty loops can be removed</p>



<a name="158050011"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/termination%20c%20vs%20c%2B%2B/near/158050011" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/termination.20c.20vs.20c.2B.2B.html#158050011">(Feb 11 2019 at 17:55)</a>:</h4>
<p>but if it is not [constant], it is fine if it is not considered as such [side-effect].</p>



<a name="158050078"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/termination%20c%20vs%20c%2B%2B/near/158050078" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/termination.20c.20vs.20c.2B.2B.html#158050078">(Feb 11 2019 at 17:56)</a>:</h4>
<p><code>while(x) { }</code> where <code>x</code> is not a constant expression can be assumed to terminate</p>



<a name="158050118"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/termination%20c%20vs%20c%2B%2B/near/158050118" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/termination.20c.20vs.20c.2B.2B.html#158050118">(Feb 11 2019 at 17:57)</a>:</h4>
<p>That’s what I said <span aria-label="slight smile" class="emoji emoji-1f642" role="img" title="slight smile">:slight_smile:</span></p>



<a name="158050120"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/termination%20c%20vs%20c%2B%2B/near/158050120" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/termination.20c.20vs.20c.2B.2B.html#158050120">(Feb 11 2019 at 17:57)</a>:</h4>
<p>this is different from it being undefined behavior</p>



<a name="158050125"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/termination%20c%20vs%20c%2B%2B/near/158050125" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/termination.20c.20vs.20c.2B.2B.html#158050125">(Feb 11 2019 at 17:57)</a>:</h4>
<p>which is what you meant, yes</p>



<a name="158050179"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/termination%20c%20vs%20c%2B%2B/near/158050179" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/termination.20c.20vs.20c.2B.2B.html#158050179">(Feb 11 2019 at 17:58)</a>:</h4>
<p><span class="user-mention" data-user-id="123586">@nagisa</span> so I guess the infinite loop example is ok for both C and C++</p>



<a name="158050212"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/termination%20c%20vs%20c%2B%2B/near/158050212" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/termination.20c.20vs.20c.2B.2B.html#158050212">(Feb 11 2019 at 17:58)</a>:</h4>
<p>in C++, it is UB, so anything is allowed</p>



<a name="158050218"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/termination%20c%20vs%20c%2B%2B/near/158050218" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/termination.20c.20vs.20c.2B.2B.html#158050218">(Feb 11 2019 at 17:58)</a>:</h4>
<p>in C, it can be assumed to terminate, but the function is <code>noreturn</code></p>



<a name="158050228"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/termination%20c%20vs%20c%2B%2B/near/158050228" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/termination.20c.20vs.20c.2B.2B.html#158050228">(Feb 11 2019 at 17:58)</a>:</h4>
<p>so that would mean that it would return, which would be undefined behavior for a <code>noreturn</code> function</p>



<a name="158050234"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/termination%20c%20vs%20c%2B%2B/near/158050234" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/termination.20c.20vs.20c.2B.2B.html#158050234">(Feb 11 2019 at 17:58)</a>:</h4>
<p>side-effect and terminate are two distinct things.</p>



<a name="158050264"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/termination%20c%20vs%20c%2B%2B/near/158050264" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/termination.20c.20vs.20c.2B.2B.html#158050264">(Feb 11 2019 at 17:59)</a>:</h4>
<p>termination is a side-effect, but not the other way around.</p>



<a name="158050278"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/termination%20c%20vs%20c%2B%2B/near/158050278" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/termination.20c.20vs.20c.2B.2B.html#158050278">(Feb 11 2019 at 17:59)</a>:</h4>
<p>the function <code>foo</code> is <code>noreturn,pure</code>, that is, it is not allowed to return, and it is not allowed to have side-effects</p>



<a name="158050351"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/termination%20c%20vs%20c%2B%2B/near/158050351" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/termination.20c.20vs.20c.2B.2B.html#158050351">(Feb 11 2019 at 18:00)</a>:</h4>
<p>right, and therefore <code>pure</code> function must not have an infinite loop in it.</p>



<a name="158050356"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/termination%20c%20vs%20c%2B%2B/near/158050356" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/termination.20c.20vs.20c.2B.2B.html#158050356">(Feb 11 2019 at 18:00)</a>:</h4>
<p>the question is whether calling it is always UB</p>



<a name="158050358"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/termination%20c%20vs%20c%2B%2B/near/158050358" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/termination.20c.20vs.20c.2B.2B.html#158050358">(Feb 11 2019 at 18:00)</a>:</h4>
<p>in both C and C++</p>



<a name="158050376"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/termination%20c%20vs%20c%2B%2B/near/158050376" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/termination.20c.20vs.20c.2B.2B.html#158050376">(Feb 11 2019 at 18:00)</a>:</h4>
<p>ah no, only in C</p>



<a name="158050396"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/termination%20c%20vs%20c%2B%2B/near/158050396" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/termination.20c.20vs.20c.2B.2B.html#158050396">(Feb 11 2019 at 18:01)</a>:</h4>
<p>My initial reaction is that it is, but I haven’t thought much about it. It applies to both C and C++.</p>



<a name="158050433"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/termination%20c%20vs%20c%2B%2B/near/158050433" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/termination.20c.20vs.20c.2B.2B.html#158050433">(Feb 11 2019 at 18:01)</a>:</h4>
<p>C++ has a <code>[[noreturn]]</code> attribute which means what you’d expect. And implementing such function requires a side-effect AFAICT.</p>



<a name="158050437"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/termination%20c%20vs%20c%2B%2B/near/158050437" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/termination.20c.20vs.20c.2B.2B.html#158050437">(Feb 11 2019 at 18:01)</a>:</h4>
<p>note that you don't have to use <code>while(x) {}</code>, one can also use <code>for(;;)</code> which in C has no effects AFAICT</p>



<a name="158050511"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/termination%20c%20vs%20c%2B%2B/near/158050511" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/termination.20c.20vs.20c.2B.2B.html#158050511">(Feb 11 2019 at 18:02)</a>:</h4>
<p>basically the question is: can a function be <code>noreturn</code> and also have no side-effects?</p>



<a name="158050522"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/termination%20c%20vs%20c%2B%2B/near/158050522" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/termination.20c.20vs.20c.2B.2B.html#158050522">(Feb 11 2019 at 18:03)</a>:</h4>
<p>to which my answer is "probably no, but I haven’t thought about it that much to tell for sure”</p>



<a name="158050542"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/termination%20c%20vs%20c%2B%2B/near/158050542" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/termination.20c.20vs.20c.2B.2B.html#158050542">(Feb 11 2019 at 18:03)</a>:</h4>
<p>so what could such a function do? it could loop forever in C, but if it does that without side-effects, the compiler can remove the loop</p>



<a name="158050549"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/termination%20c%20vs%20c%2B%2B/near/158050549" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/termination.20c.20vs.20c.2B.2B.html#158050549">(Feb 11 2019 at 18:03)</a>:</h4>
<p>which would make it try to return, which would be UB</p>



<a name="158050601"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/termination%20c%20vs%20c%2B%2B/near/158050601" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/termination.20c.20vs.20c.2B.2B.html#158050601">(Feb 11 2019 at 18:04)</a>:</h4>
<p>it has to do something that does not return, even in the absence of side-effects</p>



<a name="158050614"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/termination%20c%20vs%20c%2B%2B/near/158050614" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/termination.20c.20vs.20c.2B.2B.html#158050614">(Feb 11 2019 at 18:04)</a>:</h4>
<p>I don't think that's possible in C (either you do something that has side-effects, or the function will return_</p>



<a name="158050618"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/termination%20c%20vs%20c%2B%2B/near/158050618" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/termination.20c.20vs.20c.2B.2B.html#158050618">(Feb 11 2019 at 18:04)</a>:</h4>
<p>right.</p>



<a name="158052325"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/termination%20c%20vs%20c%2B%2B/near/158052325" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Nicole Mazzuca <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/termination.20c.20vs.20c.2B.2B.html#158052325">(Feb 11 2019 at 18:30)</a>:</h4>
<p>I can't tell if this helps, but you can do local side effects while still being pure (see: Haskell, for example). The following is a program without UB in C++:</p>
<div class="codehilite"><pre><span></span><span class="kt">void</span> <span class="nf">do_no_effect</span><span class="p">()</span> <span class="p">[[</span><span class="n">noreturn</span><span class="p">]]</span> <span class="n">__attribute</span><span class="p">((</span><span class="k">const</span><span class="p">))</span> <span class="p">{</span>
  <span class="kt">int</span> <span class="k">volatile</span> <span class="n">x</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
  <span class="k">for</span> <span class="p">(;;)</span> <span class="p">{</span>
    <span class="n">x</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
  <span class="p">}</span>
<span class="p">}</span>
</pre></div>



<a name="158052597"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/termination%20c%20vs%20c%2B%2B/near/158052597" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/termination.20c.20vs.20c.2B.2B.html#158052597">(Feb 11 2019 at 18:34)</a>:</h4>
<p><span class="user-mention" data-user-id="125253">@Nicole Mazzuca</span> non-escaping “side-effects” are permitted by the LLVM’s definition of "const" and "pure", not sure about C/C++/gcc, though.</p>



<a name="158052687"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/termination%20c%20vs%20c%2B%2B/near/158052687" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Nicole Mazzuca <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/termination.20c.20vs.20c.2B.2B.html#158052687">(Feb 11 2019 at 18:35)</a>:</h4>
<p><span class="user-mention" data-user-id="123586">@nagisa</span> they must be</p>



<a name="158052750"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/termination%20c%20vs%20c%2B%2B/near/158052750" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Nicole Mazzuca <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/termination.20c.20vs.20c.2B.2B.html#158052750">(Feb 11 2019 at 18:36)</a>:</h4>
<p>The reason that __attribute((const)) and __attribute((pure)) exist is to allow the implementation to remove function calls</p>



<a name="158052775"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/termination%20c%20vs%20c%2B%2B/near/158052775" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Nicole Mazzuca <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/termination.20c.20vs.20c.2B.2B.html#158052775">(Feb 11 2019 at 18:36)</a>:</h4>
<p>removing a function call which doesn't change global state in any way is totally reasonable</p>



<a name="158052814"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/termination%20c%20vs%20c%2B%2B/near/158052814" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Nicole Mazzuca <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/termination.20c.20vs.20c.2B.2B.html#158052814">(Feb 11 2019 at 18:37)</a>:</h4>
<p>hmm...</p>



<a name="158052821"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/termination%20c%20vs%20c%2B%2B/near/158052821" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Nicole Mazzuca <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/termination.20c.20vs.20c.2B.2B.html#158052821">(Feb 11 2019 at 18:37)</a>:</h4>
<p>no, I see what you're saying</p>



<a name="158053024"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/termination%20c%20vs%20c%2B%2B/near/158053024" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/termination.20c.20vs.20c.2B.2B.html#158053024">(Feb 11 2019 at 18:39)</a>:</h4>
<p>I just genuinely don’t know to claim either way. I just know that LLVM specifically is just fine with that.</p>



<a name="158053401"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/termination%20c%20vs%20c%2B%2B/near/158053401" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/termination.20c.20vs.20c.2B.2B.html#158053401">(Feb 11 2019 at 18:44)</a>:</h4>
<p>i've posted a summary comment<br>
<a href="https://github.com/rust-lang/rust/pull/58327#discussion_r" target="_blank" title="https://github.com/rust-lang/rust/pull/58327#discussion_r">https://github.com/rust-lang/rust/pull/58327#discussion_r</a></p>



<a name="158053449"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/termination%20c%20vs%20c%2B%2B/near/158053449" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/termination.20c.20vs.20c.2B.2B.html#158053449">(Feb 11 2019 at 18:45)</a>:</h4>
<p>i'm not sure about the last part</p>



<a name="158053455"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/termination%20c%20vs%20c%2B%2B/near/158053455" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/termination.20c.20vs.20c.2B.2B.html#158053455">(Feb 11 2019 at 18:45)</a>:</h4>
<p>whether abort, etc. are side-effects, but I think so</p>



<a name="158053523"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/termination%20c%20vs%20c%2B%2B/near/158053523" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/termination.20c.20vs.20c.2B.2B.html#158053523">(Feb 11 2019 at 18:46)</a>:</h4>
<p><code>abort</code> is definitely considered to be a global side-effect.</p>



<a name="158059400"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/termination%20c%20vs%20c%2B%2B/near/158059400" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Nicole Mazzuca <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/termination.20c.20vs.20c.2B.2B.html#158059400">(Feb 11 2019 at 19:54)</a>:</h4>
<p><a href="https://twitter.com/GyrosGeier/status/1095037097533153280?s=19" target="_blank" title="https://twitter.com/GyrosGeier/status/1095037097533153280?s=19">https://twitter.com/GyrosGeier/status/1095037097533153280?s=19</a></p>
<div class="inline-preview-twitter"><div class="twitter-tweet"><a href="https://twitter.com/GyrosGeier/status/1095037097533153280?s=19" target="_blank"><img class="twitter-avatar" src="https://pbs.twimg.com/profile_images/639998450/04545d6_normal.jpg"></a><p><a href="https://twitter.com/ubsanitizer" target="_blank" title="https://twitter.com/ubsanitizer">@ubsanitizer</a> My interpretation would be similar to #84210. Essentially, not UB, but no valid use case exists either.</p><span>- Simon Richter (@GyrosGeier)</span></div></div>



<a name="158063400"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/termination%20c%20vs%20c%2B%2B/near/158063400" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/termination.20c.20vs.20c.2B.2B.html#158063400">(Feb 11 2019 at 20:41)</a>:</h4>
<blockquote>
<p>can be assumed to terminate [...] this is different from it being undefined behavior</p>
</blockquote>
<p>I don't see the difference. "x is UB" is exactly the same statement as "x can be assumed not to happen"</p>



<a name="158063419"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/termination%20c%20vs%20c%2B%2B/near/158063419" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/termination.20c.20vs.20c.2B.2B.html#158063419">(Feb 11 2019 at 20:41)</a>:</h4>
<p>so, "can be assumed to terminate" = "non-termination is UB"</p>



<a name="158064390"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/termination%20c%20vs%20c%2B%2B/near/158064390" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Nicole Mazzuca <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/termination.20c.20vs.20c.2B.2B.html#158064390">(Feb 11 2019 at 20:53)</a>:</h4>
<p>This is the reading of the C++ standards committee</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>